<template>
	<view>
		<!-- 头部 -->
		<view class="searchHead">
			<u-search :label="SearchList[0][searchIndex]" height="40px" v-model="searchText" @search="searChange('click')"
			@labelClick="labelClick" :showAction="false" @clear="searchClear" @change="searChange('')">
			</u-search>
		</view>
		<template v-if="JSON.stringify(userInfo)!='{}'">
			<my-scroll-list  ref="business" requestUrl="/yzyBusinessDistrict/list" HearHeight="55">
				<template #ScrollMyList="{contentScrollList}">
					<view class="contentItem publicBox" v-for="(item,index) in contentScrollList" :key="index" @click="GoToPage(item)">
						<view class="left">
							<my-image :imageUrl="avatarNameUrl+item.avatarPath" imgHeight="80" imgWidth="80"></my-image>
							<!-- <image class="img" :src="avatarNameUrl+item.avatarPath"></image> -->
						</view>
						<view class="right">
							<view class="shop ellipsis">{{item.avatarName}}</view>
							<view class="local ellipsis">{{item.location}}</view>
						</view>
					</view>
			    </template>
			</my-scroll-list>
		</template>
		
		<!-- <u-action-sheet cancelText="取消" :actions="SearchList" @close="SearchType=false"
		:closeOnClickAction="true" :show="SearchType" @select="selectSearch">
		</u-action-sheet> -->
		<u-picker :show="SearchType" :columns="SearchList" @confirm="selectSearch" @cancel="SearchType=false"></u-picker>
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	import {skipPage} from '@/utils/common.js'
	export default {
		data() {
			return {
				timer:null,// 延时器
				avatarNameUrl:uni.$u.http.config.baseURL,
				SearchType:false,//是否展开选择
				searchIndex:0,
				// SearchList:[
				// 	{name:'店铺名称',searchName:'avatarName',id:0},
				// 	{name:'所在位置',searchName:'location',id:1}
				// ],
				SearchList:[['店铺名称','所在位置']],
				searchText:'',
			};
		},
		computed:{
			...mapState('m_user',['userInfo'])
		},
		methods:{
			GoToPage(item){
				skipPage(`/subpkg/DetailsPage/DetailsPage?title=商户详情&id=${item.id}`)
			},
			labelClick(){// 点击左边label 搜索左侧文本信息
				this.SearchType=true
			},
			selectSearch(item){//搜索类型 点击确定按钮
				this.searchIndex=item.indexs[0]
				this.SearchType=false
				this.inputSearch('click')
			},
			searChange(type){//搜索输入框内容发生变化时触发
			    this.inputSearch(type)
			},
			searchClear(){//清空内容
				this.searchText=''
			},
			inputSearch(type='',value=this.searchText){
				if(!value&&type){
					return
				}
				let param={
					avatarName:value,
					location:value,
				}
				if(this.searchIndex==0){//店铺
					delete param.location
				}else{
					delete param.avatarName
				}
				clearTimeout(this.timer)
				this.timer = setTimeout(() => {
				    if(!value){
						this.$refs.business.searParams={}
				    	this.$refs.business.getListData(false,true)
				    	return
				    }
					this.$refs.business.searParams=param
				    this.$refs.business.getListData(false,true,param)
				}, 500)
			},
			GoToLogin(){
				uni.showModal({
					title: '提示',
					confirmText: "去登录", // 确认按钮的文字 
					showCancel:false,
					content: "你还未登录，登陆后享受更多服务",
					complete() {
						uni.$u.route('/subpkg/simplePage/simplePage', {
							title: '登录',
							IfonShow: 'true'
						});
					}
				})
			}
		},
		onShow() {
			if(JSON.stringify(this.userInfo)=="{}"){
				this.GoToLogin()
			}
		}
	}
</script>

<style lang="scss" scoped>
// 头部搜索
.searchHead{
	background:#fff;
	border-bottom: 1px solid rgb(238, 238, 238);
	box-shadow: 0px 0px 5px 1px rgba(217, 217, 217, 0.5 );
	height:55px;
	padding:0 25px;
	box-sizing: border-box;
	display: flex;
	align-items: center;
}
// 列表展示
.contentItem{
	display:flex;
	align-items: center;
	padding:5px 0;
	.left{
		height:80px;
		width:80px;
		border-radius:50%;
		overflow: hidden;
		margin:0 25rpx;
		.img{
			height:100%;
			width:100%;
		}
	}
	.right{
		display:flex;
		flex-direction: column;
		width:520rpx;
		justify-content: space-between;
		.shop{
			font-size:34rpx;
			margin-bottom:5px;
		}
		.local{
			font-size:26rpx;
			color:#6e6158;
				
		}
	}
}
</style>
